package edu.qd.learn.day08;


import java.math.BigInteger;

/**
 * @author 布衣
 */
public class LearnRecursive {

    // 10 + 1

    public int sum() {
        int sum = 0;
        for (int i = 1; i <= 10; i++) {
            sum += i;
        }
        return sum;
    }

    public int sum1(int n) {
        //1 终止条件
        if (n == 1) {
            return 1;
        }
        return n + sum1(n - 1);
    }

    //递归  斐波那契数列
    public int fib(int n) {
        if (n <= 2) {
            return 1;
        }
        return fib(n - 1) + fib(n - 2);
    }

    public int fib2(int n) {
        if (n <= 2) {
            return 1;
        }
        return fib2(n - 1) + fib2(n - 2);
    }

    public BigInteger fib1(long month) {
        if (month < 0) {
            throw new RuntimeException("月份不能小于0或者大于48");
        }
        if (month <= 2) {
            return new BigInteger("1");
        }
        BigInteger n = new BigInteger("1"), m = new BigInteger("1");
        BigInteger sum = new BigInteger("0");
        for (int i = 3; i <= month; i++) {
            sum =n.add(m);
            System.out.printf("第%d几个月，共有兔子%d对 \n", i, sum);
            n = m;
            m = sum;
        }
        return sum;
    }

    public static void main(String[] args) {
        LearnRecursive l = new LearnRecursive();
        l.sum1(3);
        System.out.println(l.fib1(100));
    }
}
